
#include "map.h"

#include <fstream> //for files

bool Map::loadMap(char * a_nameOfMap){
	ifstream file(a_nameOfMap);

	if(!file.is_open())
	{
		cout << "not open or error couldn't open file" << endl;
		return false;
	}
	//otherwise, assume the data is good...
	file >> m_width;
	file >> m_height;
	file.ignore(1000, '\n'); //ignore the rest of the line

	m_data = new char * [m_height];
	
	//load the 2d data into the map 2d array
	for(int r = 0; r < m_height; ++r)
	{
		m_data[r] = new char[m_width];
		for(int c= 0; c < m_width; ++c)
		{
			m_data[r][c] = file.get();
		}
		file.ignore(1000, '\n');
	}
	file.close();

	return true;
}
void Map::release(){
	if(m_data)
	{
		for(int r = 0; r < m_height; ++r)
		{
			delete m_data[r];
		}
		delete m_data;

		m_data = NULL;
	}
	m_width = 0;
	m_height = 0;
}